using Engine;
using Game;
using GameEntitySystem;

namespace SCIENEW {
    public class SteamBoatItemBehavior : ItemBehavior {
        public SteamBoatItemBehavior(Project project) : base(project) { }

        public override bool OnUse(Ray3 ray, ComponentMiner componentMiner) {
            int activeBlockValue = componentMiner.ActiveBlockValue;
            TerrainRaycastResult? result = componentMiner.Raycast<TerrainRaycastResult>(ray, RaycastMode.Digging);
            Entity entity;
            Vector3 position;
            if (result.HasValue) {
                position = result.Value.HitPoint();
                if (activeBlockValue == ItemsBlockManager.IdMap["SteamBoat"]) {
                    entity = DatabaseManager.CreateEntity(Project, "SteamBoat", true);
                    entity.FindComponent<ComponentFrame>(true).Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0f);
                    entity.FindComponent<ComponentBody>(true).Position = position;
                    entity.FindComponent<ComponentSpawn>(true).SpawnDuration = 0f;
                    Project.AddEntity(entity);
                    componentMiner.RemoveActiveTool(1);
                    return true;
                }
            }
            return false;
        }
    }
}